package com.pe.dao.user;

import java.util.List;

import javax.persistence.EntityManager;

import com.pe.model.user.User;
import com.pe.model.user.UserImpl;
import com.pe.shared.EMF;

public class UserFactoryImpl implements UserFactory {

	EntityManager em;
	
	public UserFactoryImpl() {
		this.em = EMF.get().createEntityManager();
	}
	public EntityManager getEm() {
		return em;
	}
	@Override
	public void setEm(EntityManager em) {
		this.em = em;
	}

	@Override
	public User getUser(User user) {
		return em.find(UserImpl.class, user.getId());
	}

	@Override
	public void registerUser(User user) {
		em.persist(user);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<User> getUsers() {
		return em.createQuery("select from UserImpl").getResultList();
	}

}
